home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
bookmarks
/
bookmarksutils.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
7KB
|
234 lines
/*
* bookmarksutils.js
*
* @author david marteau <marteau.david@free.fr>
* @copyright 2005-2006 Yoono
*/
const YOONO_NS = "http://www.yoono.com/bookmarks/1.0";
function ynBookmarksUtils()
{
const CI = Components.interfaces;
const CL = Components.classes;
const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
const NC_NS = "http://home.netscape.com/NC-rdf#";
this._NC_NS = NC_NS;
this._console = CL['@mozilla.org/consoleservice;1'].getService(CI.nsIConsoleService);
this._rdf = CL['@mozilla.org/rdf/rdf-service;1'].getService(CI.nsIRDFService);
this._rdfc = CL['@mozilla.org/rdf/container-utils;1'].getService(CI.nsIRDFContainerUtils);
this._prefs = CL['@mozilla.org/preferences-service;1'].getService(CI.nsIPrefService);
this._prefs.QueryInterface(CI.nsIPrefBranch);
this._bmds = this._rdf.GetDataSource("rdf:bookmarks");
this._ds = this._bmds.QueryInterface(CI.nsIBookmarksService);
this._typeRes=this._rdf.GetResource(RDF_NS+"type");
// RDF types
this._bookmarkType =this._rdf.GetResource(NC_NS+"Bookmark");
this._folderType =this._rdf.GetResource(NC_NS+"Folder");
this._livemarkType =this._rdf.GetResource(NC_NS+"Livemark");
this._separatorType =this._rdf.GetResource(NC_NS+"BookmarkSeparator");
// RDF bookmarks arcs
/*
this._urlRes = this._rdf.GetResource(NC_NS+"URL");
this._nameRes = this._rdf.GetResource(NC_NS+"Name");
this._descRes = this._rdf.GetResource(NC_NS+"Description");
this._keywordRes = this._rdf.GetResource(NC_NS+"ShortcutURL");
this._iconRes = this._rdf.GetResource(NC_NS+"Icon");
this._feedRes = this._rdf.GetResource(NC_NS+"FeedURL");
this._sideRes = this._rdf.GetResource(NC_NS+"WebPanel");
this._dateRes = this._rdf.GetResource(NC_NS+"BookmarkAddDate");
*/
}
ynBookmarksUtils.prototype =
{
// RDF helper
/**
* return string value from rdf Literal or resource
*/
rdfStringData : function( aLiteralOrResource )
{
const CI = Components.interfaces;
try {
var obj = aLiteralOrResource.QueryInterface(CI.nsIRDFLiteral);
return obj.Value;
}
catch (e)
{
try {
obj = aLiteralOrResource.QueryInterface(CI.nsIRDFResource);
return obj.Value;
}
catch (e) {}
}
return "";
},
get RDF() { return this._rdf; },
get RDFC() { return this._rdfc; },
get BKMS() { return this._ds; },
get BMDS() { return this._bmds; },
getArc : function( name ) {
return this._rdf.GetResource(this._NC_NS+name);
},
getProperty : function( aRes, aArc ) {
return this.rdfStringData(
this._bmds.GetTarget(aRes,aArc,true));
},
getDateLiteral : function( aRes, aArc ) {
var obj = this._ds.GetTarget(aRes,aArc,true);
return obj.QueryInterface(Components.interfaces.nsIRDFDate).Value;
},
getPropertyByName : function( aRes, aName ) {
return this.rdfStringData(
this._bmds.GetTarget(aRes,
this.getArc(aName),true));
},
getType : function( aResource )
{
var type = this.rdfStringData(this._ds.GetTarget(aResource,this._typeRes,true));
if (type != "")
type = type.split("#")[1];
if(type=="Folder" && aResource == this._ds.getBookmarksToolbarFolder())
type = "ToolbarFolder";
return type;
},
getContainer : function( aResource )
{
var container = Components.classes["@mozilla.org/rdf/container;1"]
.createInstance(Components.interfaces.nsIRDFContainer);
container.Init(this._ds,aResource);
return container;
},
getRoot : function() {
return this._rdf.GetResource("NC:BookmarksRoot");
},
getToolBarFolder : function() {
return this._ds.getBookmarksToolbarFolder();
},
getBookmarkedResource : function( aArc, aValue )
{
var literal = this._rdf.GetLiteral(aValue);
var res = this._bmds.GetSource(aArc,literal,true);
if(res && this._ds.isBookmarkedResource(res))
return res;
return null;
},
isBookmarked : function( aArc, aValue ) {
return this.getBookmarkedResource(aArc,aValue) != null;
},
createFolder : function( folderName, folderDesc, parentRes )
{
var res = (parentRes ?
this._ds.createFolderInContainer(folderName,parentRes,0):
this._ds.createFolder(folderName));
if(res && folderDesc)
{
const descRes = this.getArc("Description");
this._bmds.Assert(res,descRes,
this._rdf.GetLiteral(folderDesc),
true);
}
return res;
},
createBookmark : function( bmName, bmURL,bmshortcutURL,bmDescription,
parentRes )
{
var res = (parentRes ?
this._ds.createBookmarkInContainer(bmName,bmURL,bmshortcutURL,bmDescription,'',null,parentRes,null):
this._ds.createBookmark(bmName,bmURL,bmshortcutURL,bmDescription,'', null));
return res;
},
createLivemark : function( lvName, lvURL,lvRSSURL,lvDescription,
parentRes )
{
var res = (parentRes ?
this._ds.createLivemarkInContainer(lvName,lvURL,lvRSSURL,lvDescription,parentRes,null):
this._ds.createLivemark(lvName,lvURL,lvRSSURL,lvDescription));
return res;
},
createSeparator : function()
{
return this._ds.createSeparator();
},
isOrdinalProperty : function ( aResource ) {
return this._rdfc.IsOrdinalProperty(aResource);
},
get prefs() { return this._prefs; },
getPref : function( prefName, defaultValue )
{
try {
var prefs = this._prefs;
switch(prefs.getPrefType(prefName))
{
case prefs.PREF_STRING : return prefs.getCharPref(prefName);
case prefs.PREF_BOOL : return prefs.getBoolPref(prefName);
case prefs.PREF_INT : return prefs.getIntPref (prefName);
}
} catch(e) {}
return defaultValue;
},
beginUpdateBatch : function() { this._bmds.beginUpdateBatch(); },
endUpdateBatch : function() {
this._bmds.endUpdateBatch();
try {
//this._ds.transactionManager.clear();
} catch(err) {}
},
flush : function()
{
var remote = this._bmds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
setTimeout(function () {remote.Flush();}, 100);
},
error : function( topic, message )
{
var msg = topic+"\n"+message;
this._console.logStringMessage(msg);
dump(msg+'\n');
}
};